﻿<template>
  <div>
    <a-card :bordered="false" :bodyStyle="tstyle">

      <div class="table-page-search-wrapper" v-if="hasPerm('IcInfoExtend:page')">
        <a-form layout="inline">
          <a-row :gutter="48">
            <a-col :md="8" :sm="24">
              <a-form-item label="CRM_ID ">
                <a-input v-model="queryParam.crmId" allow-clear placeholder="请输入CRM_ID "/>
              </a-form-item>
            </a-col>
            <a-col :md="8" :sm="24">
              <a-form-item label="TIP_TYPE ">
                <a-input v-model="queryParam.tipType" allow-clear placeholder="请输入TIP_TYPE "/>
              </a-form-item>
            </a-col><template v-if="advanced"><a-col :md="8" :sm="24">
                <a-form-item label="TIP_LIMIT ">
                  <a-date-picker style="width: 100%" placeholder="请选择TIP_LIMIT " v-model="queryParam.tipLimitDate" @change="onChangetipLimit"/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="FIELD_01 ">
                  <a-input v-model="queryParam.field01" allow-clear placeholder="请输入FIELD_01 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="FIELD_02 ">
                  <a-input v-model="queryParam.field02" allow-clear placeholder="请输入FIELD_02 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="FIELD_03 ">
                  <a-input v-model="queryParam.field03" allow-clear placeholder="请输入FIELD_03 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="TIP_CODE ">
                  <a-input v-model="queryParam.tipCode" allow-clear placeholder="请输入TIP_CODE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="TIP_MESSAGE ">
                  <a-input v-model="queryParam.tipMessage" allow-clear placeholder="请输入TIP_MESSAGE "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="卡号 ">
                  <a-input v-model="queryParam.icNo" allow-clear placeholder="请输入卡号 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="单位ID ">
                  <a-input v-model="queryParam.companyId" allow-clear placeholder="请输入单位ID "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="单位编码 ">
                  <a-input v-model="queryParam.companyCode" allow-clear placeholder="请输入单位编码 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="单位名称 ">
                  <a-input v-model="queryParam.companyName" allow-clear placeholder="请输入单位名称 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label="01 个人发票 02 单位发票 00 不开票 ">
                  <a-input v-model="queryParam.invoiceType" allow-clear placeholder="请输入01 个人发票 02 单位发票 00 不开票 "/>
                </a-form-item>
              </a-col>
              <a-col :md="8" :sm="24">
                <a-form-item label=" 1 正常 0 删除 ">
                  <a-input v-model="queryParam.status" allow-clear placeholder="请输入 1 正常 0 删除 "/>
                </a-form-item>
              </a-col>            </template>

            <a-col :md="8" :sm="24" >
              <span class="table-page-search-submitButtons">
                <a-button type="primary" @click="$refs.table.refresh(true)" >查询</a-button>
                <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
                <a @click="toggleAdvanced" style="margin-left: 8px"> {{ advanced ? '收起' : '展开' }}
                  <a-icon :type="advanced ? 'up' : 'down'"/>
                </a>
              </span>
            </a-col>

          </a-row>
        </a-form>
      </div>
    </a-card>
    <a-card :bordered="false">
      <s-table
        ref="table"
        :columns="columns"
        :data="loadData"
        :alert="true"
        :rowKey="(record) => record.iD"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }">
        <template class="table-operator" slot="operator" v-if="hasPerm('IcInfoExtend:add')" >
          <a-button type="primary" v-if="hasPerm('IcInfoExtend:add')" icon="plus" @click="$refs.addForm.add()">新增会员其他信息</a-button>
        </template>
        <span slot="action" slot-scope="text, record">
          <a v-if="hasPerm('IcInfoExtend:edit')" @click="$refs.editForm.edit(record)">编辑</a>
          <a-divider type="vertical" v-if="hasPerm('IcInfoExtend:edit') & hasPerm('IcInfoExtend:delete')"/>
          <a-popconfirm v-if="hasPerm('IcInfoExtend:delete')" placement="topRight" title="确认删除？" @confirm="() => IcInfoExtendDelete(record)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </s-table>
      <add-form ref="addForm" @ok="handleOk" />
      <edit-form ref="editForm" @ok="handleOk" />
    </a-card>
  </div>
</template>
<script>
  import { STable } from '@/components'
  import moment from 'moment'
  import { IcInfoExtendPage, IcInfoExtendDelete } from '@/api/modular/main/IcInfoExtendManage'
  import addForm from './addForm.vue'
  import editForm from './editForm.vue'
  export default {
    components: {
      STable,
      addForm,
      editForm
    },
    data () {
      return {
        advanced: false, // 高级搜索 展开/关闭
        queryParam: {},
        columns: [
          {
            title: 'CRM_ID ',
            align: 'center',
            dataIndex: 'crmId'
          },
          {
            title: 'TIP_TYPE ',
            align: 'center',
            dataIndex: 'tipType'
          },
          {
            title: 'TIP_LIMIT ',
            align: 'center',
            dataIndex: 'tipLimit'
          },
          {
            title: 'FIELD_01 ',
            align: 'center',
            dataIndex: 'field01'
          },
          {
            title: 'FIELD_02 ',
            align: 'center',
            dataIndex: 'field02'
          },
          {
            title: 'FIELD_03 ',
            align: 'center',
            dataIndex: 'field03'
          },
          {
            title: 'TIP_CODE ',
            align: 'center',
            dataIndex: 'tipCode'
          },
          {
            title: 'TIP_MESSAGE ',
            align: 'center',
            dataIndex: 'tipMessage'
          },
          {
            title: '卡号 ',
            align: 'center',
            dataIndex: 'icNo'
          },
          {
            title: '单位ID ',
            align: 'center',
            dataIndex: 'companyId'
          },
          {
            title: '单位编码 ',
            align: 'center',
            dataIndex: 'companyCode'
          },
          {
            title: '单位名称 ',
            align: 'center',
            dataIndex: 'companyName'
          },
          {
            title: '01 个人发票 02 单位发票 00 不开票 ',
            align: 'center',
            dataIndex: 'invoiceType'
          },
          {
            title: ' 1 正常 0 删除 ',
            align: 'center',
            dataIndex: 'status'
          }
        ],
        tstyle: { 'padding-bottom': '0px', 'margin-bottom': '10px' },
        // 加载数据方法 必须为 Promise 对象
        loadData: parameter => {
          return IcInfoExtendPage(Object.assign(parameter, this.switchingDate())).then((res) => {
            return res.data
          })
        },
        selectedRowKeys: [],
        selectedRows: []
      }
    },
    created () {
      if (this.hasPerm('IcInfoExtend:edit') || this.hasPerm('IcInfoExtend:delete')) {
        this.columns.push({
          title: '操作',
          width: '150px',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        })
      }
    },
    methods: {
      moment,
      /**
       * 查询参数组装
       */
      switchingDate () {
        const queryParamtipLimit = this.queryParam.tipLimitDate
        if (queryParamtipLimit != null) {
            this.queryParam.tipLimit = moment(queryParamtipLimit).format('YYYY-MM-DD')
            if (queryParamtipLimit.length < 1) {
                delete this.queryParam.tipLimit
            }
        }
        const obj = JSON.parse(JSON.stringify(this.queryParam))
        return obj
      },
      IcInfoExtendDelete (record) {
        IcInfoExtendDelete(record).then((res) => {
          if (res.success) {
            this.$message.success('删除成功')
            this.$refs.table.refresh()
          } else {
            this.$message.error('删除失败') // + res.message
          }
        })
      },
      toggleAdvanced () {
        this.advanced = !this.advanced
      },
      onChangetipLimit(date, dateString) {
        this.tipLimitDateString = dateString
      },
      handleOk () {
        this.$refs.table.refresh()
      },
      onSelectChange (selectedRowKeys, selectedRows) {
        this.selectedRowKeys = selectedRowKeys
        this.selectedRows = selectedRows
      }
    }
  }
</script>
<style lang="less">
  .table-operator {
    margin-bottom: 18px;
  }
  button {
    margin-right: 8px;
  }
</style>
